package com.ruoyi.web.controller.sj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sj.domain.PersonalData;
import com.ruoyi.sj.service.IPersonalDataService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 个人资料 信息操作处理
 * 
 * @author tyc@yanyu.com
 * @date 2018-11-28
 */
@Controller
@RequestMapping("/sj/personalData")
public class PersonalDataController extends BaseController
{
    private String prefix = "sj/personalData";
	
	@Autowired
	private IPersonalDataService personalDataService;
	
	@RequiresPermissions("sj:personalData:view")
	@GetMapping()
	public String personalData()
	{
	    return prefix + "/personalData";
	}
	
	/**
	 * 查询个人资料列表
	 */
	@RequiresPermissions("sj:personalData:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PersonalData personalData)
	{
		startPage();
        List<PersonalData> list = personalDataService.selectPersonalDataList(personalData);
		return getDataTable(list);
	}
	
	/**
	 * 新增个人资料
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存个人资料
	 */
	@RequiresPermissions("sj:personalData:add")
	@Log(title = "个人资料", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PersonalData personalData)
	{		
		return toAjax(personalDataService.insertPersonalData(personalData));
	}

	/**
	 * 修改个人资料
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		PersonalData personalData = personalDataService.selectPersonalDataById(id);
		mmap.put("personalData", personalData);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存个人资料
	 */
	@RequiresPermissions("sj:personalData:edit")
	@Log(title = "个人资料", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PersonalData personalData)
	{		
		return toAjax(personalDataService.updatePersonalData(personalData));
	}
	
	/**
	 * 删除个人资料
	 */
	@RequiresPermissions("sj:personalData:remove")
	@Log(title = "个人资料", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(personalDataService.deletePersonalDataByIds(ids));
	}
	
}
